package joodle.si;

import java.net.URL;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 * This class is a utility class with methods which provides the services for loading system resources 
 * and internationalization for the user interface layer.
 * <p><center>
 * <img src="http://ug.bcc.bilkent.edu.tr/~m_ozdal/Site/Reports_files/design_files/image015.jpg" />
 * </center></p>
 */
public class ResourceManager {
	private static ResourceBundle langBundle = ResourceBundle
			.getBundle("joodle.si.i18n");

	private ResourceManager() {
	}

	/**
	 * Loads icons for the given class
	 * @param c a class whose icons to be loaded
	 * @return an image icon
	 */
	public static Icon makeIcon(Class<?> c) {
		URL u = c.getClassLoader().getResource(c.getSimpleName().toLowerCase() + ".png");
		if(u == null)
			u = ClassLoader.getSystemResource("joodle/si/icons/none.png");
		return new ImageIcon(u);
	}

	/**
	 * Loads icons for the given icon name
	 * @param s name of the icon to be loaded
	 * @return
	 */
	public static Icon makeIcon(String s) {
		URL u = ClassLoader.getSystemResource("joodle/si/icons/" + s.toLowerCase() + ".png");
		if(u == null)
			u = ClassLoader.getSystemResource("joodle/si/icons/none.png");
		return new ImageIcon(u);
	}

	public static String message(String s) {
		return langBundle.getString(s);
	}
	
	public static void setLocale(Locale l) { 
		langBundle = ResourceBundle.getBundle("joodle.si.i18n", l);
	}
}
